// pages/mine/mine.js
var api = require("../../api.js"),
  r = "",
  app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    //tabbar
    tabbar: {},
    mineData:{}
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // app.editTabbar();
     r =this;
     r.initData();
  },
  initData:function(){
    var t= new Object();
    t.openId = getApp().globalData.wxUserInfo.openId;
     wx.request({
       url:api.mine.mine,
       data:t,
       success:function(res){
         if(res.statusCode==200&&res.data.code==200){
           var n = res.data.data;
           if(n.isBindphone==1){
             r.setData({
              phone:true,
              mineData:res.data.data
             })
           }else{
            r.setData({
               phone:false,
               mineData:res.data.data
            })
           }
           wx.setStorageSync('userGrade', n.userGrade);
          //  console.log(r.data)
         }
       }
     })
  },
  bindTel:function(){
    wx.navigateTo({
      url: "../login/login"
    })
  },
  price:function(){
    wx.navigateTo({
      url: "../price/price"
    })
  },
  parner:function(){
    r.goParner();
  },
  vip:function(){
    if(r.data.mineData.isBindphone==0){
      wx.showModal({
        title: '提示',
        content: '请先绑定手机号',
        success: function (res) {
          if (res.confirm) {
            wx.navigateTo({
              url: "../login/login"
            })
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
    }else{
      wx.navigateTo({
        url: "../viplevel/viplevel?userGrade="+r.data.mineData.userGrade
      })
    }
  },
  Coupon:function(){
    wx.navigateTo({
      url: "../coupon/coupon"
    })
  },
  company:function(){
    console.log(r.data.mineData.isCopartner)
    if(r.data.mineData.userGrade!=0){
      wx.navigateTo({
        url: "../company/company"
      })
    }else{
      wx.showModal({
        title: '提示',
        content: '请先升级用户',
        success: function (res) {
          if (res.confirm) {
            wx.navigateTo({
              url: "../viplevel/viplevel?userGrade="+r.data.mineData.userGrade
            })
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
    }
  },
  goParner:function(){
    console.log(r.data.mineData.isCopartner)
     if(r.data.mineData.isCopartner==2){
       wx.navigateTo({
         url:'../result/result'
       })
     }else if(r.data.mineData.isCopartner==0){
      wx.navigateTo({
        url:'../parner/parner'
      })

     }else{
      wx.navigateTo({
        url:'../firstparner/firstparner'
      })
     }
  }
})